package com.ys.controller.web.finance;

import com.ys.config.MenuId;
import com.ys.dto.SubGridConfigDto;
import com.ys.entity.finance.TcwManageTransact;
import com.ys.service.sys.CommonApiService;
import com.ys.vo.W;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.*;

/**
 * 管理交易类型
 */
@Controller
@RequestMapping("/web/finance/tcwManageTransact")
public class WebTcwManageTransactController {
//	private static final Logger logger = LoggerFactory.getLogger(WebTcwManageTransactController.class);

	@Autowired
	private CommonApiService<TcwManageTransact> commonApiService;


    Long menuId = MenuId.TCW_ManageTransact;
    /*
     * 新增
     */
    @GetMapping("/toAdd")
    public String toAdd(Model model, HttpServletRequest request, HttpServletResponse response){

        try {
            Map<String,Object> tcwManageTransact = new HashMap<>();
            tcwManageTransact.put("status",1);

            TcwManageTransact entity = new TcwManageTransact()
                    .setCreateTime(new Date());
            entity.setBid(commonApiService.getCommonNextUkey(MenuId.TCW_ManageTransact, "bid"));
            commonApiService.toAdd(model, entity, MenuId.TCW_ManageTransact, tcwManageTransact, null);


        } catch (Exception e) {
            e.printStackTrace();

        }
        return "finance/tcwManageTransact/tcwManageTransactAdd";
    }


    /*
     * 编辑
     */
    @GetMapping("/toEdit")
    public String toEdit(Model model, HttpServletRequest request, HttpServletResponse response,@RequestParam Map<String, Object> params){
        if (params.get("id") == null){
            return W.error(model, "id不能为空");
        }
        Long id = Long.valueOf((params.get("id").toString()));

        List<SubGridConfigDto.ButtonDto> buttonArrNew = new ArrayList<>();

        if (new TcwManageTransact().setId(id).count() == 0){
            return com.bo.vo.W.error(model, "该信息不存在!");
        }

        try {
            commonApiService.toEdit(model, id, new TcwManageTransact(), MenuId.TCW_ManageTransact, null, null);
        } catch (Exception e) {
            e.printStackTrace();
        }

        return "finance/tcwManageTransact/tcwManageTransactEdit";
    }
}